package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController//返回给前端的数据格式是jason格式
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags = "频道管理API")
public class AdChannelController {
    @Autowired
    private AdChannelService adChannelService;
    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult findAndPage(@RequestBody ChannelDto dto){
        ResponseResult byNameAndPage = adChannelService.findByNameAndPage(dto);
        return byNameAndPage;
    }
    @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }

    @PostMapping("/save")
    @ApiOperation("频道新增")
    public ResponseResult insert(@RequestBody @Validated AdChannel adChannel){
        ResponseResult insert = adChannelService.insert(adChannel);
        return insert;
    }
    @PostMapping("/update")
    @ApiOperation("频道修改")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        ResponseResult update = adChannelService.update(adChannel);
        return update;
    }
    @DeleteMapping("/del/{id}")
    @ApiOperation("频道删除")
   public ResponseResult delete(@PathVariable Integer id){
        ResponseResult delete = adChannelService.delete(id);
        return delete;

    }


}
